********************************************************************************
*This file is for the Probabilistic treatment only.
*This file does the calculations for the following tables:
* Table 7
* Table 9.
*This file produces the following figures:
* Figure 3 (a)
* Figure 4 (a)
********************************************************************************


clear all
set more off
use Comb_data_6_sessions


//calculate the expected monitoring level for drivers
sort session round group role
gen m_a_obs = m_a[_n-1] if role==2
gen m_b_obs = m_b[_n-1] if role==2
egen mon_temp_1 = rowmin(m_a_obs m_b_obs)
gen mon_temp_2 = (m_a_obs+m_b_obs)/2
gen mon_level = mon_temp_1 if is_observed == 1
replace mon_level = mon_temp_2 if is_observed == 0
drop mon_temp_1 mon_temp_2


drop if role == 1 //drop the officers.

replace mon_level=round(mon_level, 0.005) //clean up any floating point arithmetic errors.


xtset stata_id


********************************************************************************
*Table 7 (Prob treatment)
xtlogit chose_C c.mon_level##i.is_observed, pa vce(robust) corr(independent)
*Note that the variable mon_level is the V(m_a,m_b) function in the paper.
********************************************************************************


predictnl yhat1 = predict() if is_observed == 1, ci(yhat1_lcl yhat1_rcl)
predictnl yhat2 = predict() if is_observed == 0, ci(yhat2_lcl yhat2_rcl)

********************************************************************************
*Table 9 (Prob treatment tests)
//monotonicity tests
test 1.is_observed#c.mon_level + mon_level  = 0
test c.mon_level  = 0

//symmetry test
test _cons+1.is_observed + 0.4*(1.is_observed#c.mon_level + mon_level) = 0

//nontriviality tests
test _cons+1.is_observed = 0
test _cons+1.is_observed + 0.9*(1.is_observed#c.mon_level + mon_level) = 0
test _cons = 0
test _cons+ 0.9* mon_level = 0
********************************************************************************


sort mon_level
********************************************************************************
*Figure 3 (Prob treatment)
scatter yhat1 mon_level if is_observed == 1, msymbol(i O) connect(l i) || scatter yhat2 mon_level if is_observed == 0, msymbol(i O) connect(l i) ///
|| scatter yhat2_lcl mon_level if is_observed == 0, msymbol(i O) connect(l i) sort lcolor(red) || scatter yhat2_rcl mon_level if is_observed == 0,  lcolor(red) msymbol(i O) connect(l i) sort ///
|| scatter yhat1_lcl mon_level if is_observed == 1 ,msymbol(i O) connect(l i) sort lcolor(blue)|| scatter yhat1_rcl mon_level if is_observed == 1, lcolor(blue) msymbol(i O) connect(l i) sort  ///
name(obs_unobs_logit, replace)  legend( order( 1 "Observed" 2 "Unobserved")) xtitle("Expected Montioring") ytitle("Pr(C)") title("Estimated probability of choosing C")
********************************************************************************

********************************************************************************
*Figure 4 (Prob treatment)
*Note: Labels on the graphic were added ex-post
scatter yhat1 mon_level if is_observed == 1, connect(l i) msymbol(i O) || scatter yhat2 mon_level if is_observed == 0, msymbol(i O) connect(l i)  ///
name(obs_unobs_logit_xline, replace)  legend( order( 1 "Observed" 2 "Unobserved")) xtitle("Expected Montioring") ytitle("Pr(C)") title("Estimated probability of choosing C") xline(0.4)
********************************************************************************

